<?php

namespace app\api\controller\baiying;


use app\common\exception\UploadException;
use think\Config;
use think\Hook;
use baiying\lib\BYTokenClient;
use think\Db;

/**
 * 公共接口
 */
class Byaatongbu extends Bybase {

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = '*';

    protected $version = ['','v2'];

    public function _initialize() {
        parent::_initialize();
    }
    
    
    
    
    public function autoFenYeGetAiTask(){
        while(true){
            $today_start_time = strtotime("today");
            
            
            if((time() > $today_start_time + 18 * 3600) || (time() < $today_start_time + 8 * 3600)){
                usleep(5000000);
                continue;
            }

            foreach ($this->version  as $key => $value){
                $baiying_api_version = $value;
                $controller = '\app\common\controller\zhongzhuan'.$baiying_api_version.'\Autotasktongbu';
                $param = [
                    'access_token'=>$this->access_token,
                    'companyId' => $this->companyId
                ];
                $data = call_user_func_array(array($controller, 'startTongbu'),array($param));
            }


            if(!IS_CLI){
                break;
            }
            
            usleep(5000000);
        }
        
        
        
        
    }
    
    
    
    public function autoFenYeGetTaskPhone(){
        
        while(true){
            $today_start_time = strtotime("today");
            
            if((time() > $today_start_time + 18 * 3600) || (time() < $today_start_time + 8 * 3600)){
                usleep(5000000);
                continue;
            }

//            $baiying_api_version = config('zhongzhuan.baiying_api_version');
//            $this->version = ['v2'];
            foreach ($this->version  as $key => $value){
                $version = empty($value) ? 1 : 2;
                $baiying_api_version = $value;
                $controller = '\app\common\controller\zhongzhuan' .$baiying_api_version . '\Autophonetongbu' ;
                $param = [
                    'access_token'=>$this->access_token,
                    'companyId' => $this->companyId,
                    'where'=>[
                        'version'=>$version,
                    ],
                ];
                $data = call_user_func_array(array($controller, 'startTongbu'),array($param));
            }



            if(!IS_CLI){
                break;
            }

            usleep(5000000);
        }
        
       
        
        
    }
    
    

}
